﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Icms.Core;
using Icms.Core.Model;
using Icms.Core.Service;
using Icms.WebUI.Dto;
using Omu.Awesome.Mvc;

namespace Icms.WebUI.Controllers
{
    [Authorize(Roles="admin,user")]
    public class AssignmentHistoryController : BaseController
    {
        private readonly IAssignmentHistoryService s;

        public AssignmentHistoryController(IAssignmentHistoryService s)
        {
            this.s = s;
        }

        public ActionResult Index()
        {
            return View(new CaseSearchInput());
        }

        [HttpPost]
        public virtual ActionResult Search(CaseSearchInput obj, int page = 1, int ps = 10)
        {
            var criteria = new CaseSearchCriteria
                               {
                                   TypeId = obj.TypeId,
                                   TypeExamId = obj.TypeExamId,
                                   IndexId = obj.IndexId,
                                   CourtId = obj.CourtId,
                                   Number = obj.Number,
                                   RegistrationFrom = obj.RegistrationFrom,
                                   RegistrationTo = obj.RegistrationTo,
                                   PartyTypeId = obj.PartyTypeId,
                                   LastName = obj.LastName,
                                   FirstName = obj.FirstName,
                                   ReferenceNumber = obj.ReferenceNumber
                               };
            var result = s.GetPage(page, ps, criteria);
            
            

            var rows = this.RenderView("rows", result.Lst);

            return Json(new { rows, more = result.Count > page * ps });
        }

        
        public ActionResult View(Guid id)
        {
            var o = s.GetByCase(id);
            if (o == null) throw new IcmsException("this entity doesn't exist anymore");
           // ViewBag.Msg = msg;
            return View("view",o);
        }
    }
}
